package com.bootdo.clouddo.service.baidu.impl;

import java.util.List;

import org.apache.ibatis.session.RowBounds;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.bootdo.clouddo.config.TaskConfig;
import com.bootdo.clouddo.dao.baidu.ImageDao;
import com.bootdo.clouddo.domain.baidu.ImageDO;
import com.bootdo.clouddo.dto.baidu.ImageDTO;
import com.bootdo.clouddo.service.baidu.IImageService;


@Service
public class ImageServiceImpl implements IImageService {
	
	@Autowired
	private ImageDao dao;

	@Override
	public List<ImageDTO> find(Integer page, Integer size) {
		return dao.find("", "create_time", "desc", new RowBounds(page, size));
	}

	@Override
	public int save(ImageDO record) {
		return dao.insertSelective(record);
	}

	@Override
	public ImageDO get(String id) {
		return dao.selectByPrimaryKey(id);
	}
	
	@Override
	public boolean exists(String id) {
		if(TaskConfig.imageIds.contains(id)) {
			return true;
		}
		boolean e = dao.existsWithPrimaryKey(id);
		if(e)
			TaskConfig.imageIds.add(id);
		return e;
	}

	@Override
	public Integer delete(String id) {
		return dao.deleteByTag(id);
	}

}
